package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ILogActionService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.LogActionCreateValidate;
import com.mdd.admin.validate.LogActionUpdateValidate;
import com.mdd.admin.validate.LogActionSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.LogActionListedVo;
import com.mdd.admin.vo.LogActionDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;

@RestController
@RequestMapping("api/fashi_log_action")
@Api(tags = "操作日志管理")
public class LogActionController {

    @Resource
    ILogActionService iLogActionService;

    @GetMapping("/list")
    @ApiOperation(value="操作日志列表")
    public AjaxResult<PageResult<LogActionListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated LogActionSearchValidate searchValidate) throws ParseException {
        PageResult<LogActionListedVo> list = iLogActionService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="操作日志详情")
    public AjaxResult<LogActionDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        LogActionDetailVo detail = iLogActionService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "操作日志新增")
    @PostMapping("/add")
    @ApiOperation(value="操作日志新增")
    public AjaxResult<Object> add(@Validated @RequestBody LogActionCreateValidate createValidate) {
        iLogActionService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "操作日志编辑")
    @PostMapping("/edit")
    @ApiOperation(value="操作日志编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody LogActionUpdateValidate updateValidate) {
        iLogActionService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "操作日志删除")
    @PostMapping("/del")
    @ApiOperation(value="操作日志删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iLogActionService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
